package com.ych.modules.api.unAuthorInfc.item.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ych.modules.base.dbEntity.TItemShowOrderEntity;
import com.ych.modules.base.dbEntity.TUserItemEntity;
import com.ych.modules.common.entity.query.QueryUserItemEntity;
import com.ych.modules.common.service.ItemShowOrderService;
import com.ych.modules.common.service.UserItemService;
import com.ych.utils.mysqlPageUtil.PageUtils;
import com.ych.utils.serviceReturn.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2021/1/4
 * Time: 15:13
 * Description:
 */
@RestController("apiUnAuthUserItemController")
@RequestMapping("/api/unAuth/item")
@Api(tags = {"API——用户项目相关"}, description = "API——用户项目相关", position = 2)
public class UserItemController {
    @Autowired
    private UserItemService      userItemService;
    @Autowired
    private ItemShowOrderService itemShowOrderService;

    @PostMapping("/listUserItem")
    @ApiOperation(value = "项目列表查询", notes = "项目列表查询")
    public R<Page<TUserItemEntity>> listUserItem(@RequestBody QueryUserItemEntity entity) {
        try {
            entity.setStatus("0");
            Page<TUserItemEntity> page = userItemService.listUserItem(entity);
            return new R(0, "成功", new PageUtils(page));
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/decreaseCarouselItem")
    @ApiOperation(value = "轮播展示次数递减", notes = "轮播展示次数递减")
    public R<String> decreaseCarouselItem(@RequestBody String orderId) {
        try {
            itemShowOrderService.decreaseCarouselItem(orderId);
            return new R(0, "成功", null);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/listCarouselItem")
    @ApiOperation(value = "轮播列表查询", notes = "轮播列表查询")
    public R<List<TItemShowOrderEntity>> listCarouselItem() {
        try {
            List<TItemShowOrderEntity> list = itemShowOrderService.listCarouselItem();
            return new R(0, "成功", list);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/listFixedHeadlineItem")
    @ApiOperation(value = "固定头条列表查询", notes = "固定头条列表查询")
    public R<List<TItemShowOrderEntity>> listFixedHeadlineItem() {
        try {
            List<TItemShowOrderEntity> list = itemShowOrderService.listFixedHeadlineItem();
            return new R(0, "成功", list);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }
}
